<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html; charset=utf-8"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>个人基础信息登记</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script src="${pageContext.request.contextPath }/scripts/boot.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath }/scripts/LodopFuncs.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath }/scripts/PrintSample10.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath }/scripts/readcard.js" type="text/javascript"></script>
<style type="text/css">
    html, body
    {
        font-size:12px;
        padding:0;
        margin:0;
        border:0;
        height:100%;
        overflow:hidden;
    }
    .as {
	color: red;
     }
     .asLabel .mini-textbox-border,
     .asLabel .mini-textbox-input,
    .asLabel .mini-buttonedit-border,
    .asLabel .mini-buttonedit-input,
    .asLabel .mini-textboxlist-border
    {
        border:0;background:none;cursor:default;
    }
    .asLabel .mini-buttonedit-button,
    .asLabel .mini-textboxlist-close
    {
        display:none;
    }
    .asLabel .mini-textboxlist-item
    {
        padding-right:8px;
    } 
</style>
</script>
</head>
<body>
<fieldset style="border:solid 1px #aaa;padding:3px;">
  <legend >个人基础信息</legend> 
  <form id="form1" method="post">
    <input name="id" class="mini-hidden"/>
    <div style="padding-left:11px;padding-bottom:5px;">
    <table style="table-layout:fixed;">
    <tr>
    	<td style="width:10%;white-space:nowrap;text-align:right;"><span class="as">*</span>姓名：</td>
        <td style="width:20%;"><input name="aac003" class="mini-textbox asLabel" onvalidation="isNumber"  maxlength="50" style="width:90%;" 
        							  required="true" emptyText="请输入姓名"/></td>
        <td style="width:10%;white-space:nowrap;text-align:right;"><span class="as">*</span>证件类型：</td>
        <td style="width:20%;"><input name="aac058" class="mini-combobox asLabel" valueField="aaa102" textField="aaa103" 
                                      id="aac058" onvaluechanged="accept" style="width:90%;"
                                      url="${pageContext.request.contextPath }/AC01.do?method=getselectaac058&lx=AAC058"
                                      required="true" emptyText="请选择证件类型"/></td>
        <td style="width:10%;white-space:nowrap;text-align:right;"><span class="as">*</span>证件号码：</td>
        <td style="width:20%;"><input name="aac002" class="mini-textbox asLabel" onvalidation="onisLength" onvaluechanged="onNumber"  maxlength="18" 
        							  style="width:90%;" required="true" emptyText="请输入证件号"/></td>
    </tr>
    <tr>
		<td style="width:10%;text-align:right;white-space:nowrap;">证件有效期限：</td>
		<td style="width:20%;"><input name="aacc01" class="mini-datepicker asLabel" allowInput="false"  style="width:90%;"  emptyText="请输入证件有效期限"/></td>
        <td style="width:10%;white-space:nowrap;text-align:right;"><span class="as">*</span>出生日期：</td>
        <td style="width:20%;"><input name="aac006" class="mini-datepicker asLabel" allowInput="false" valueType="String"  onvalidation="onBirthday"
                                      id="aac006" required="true" emptyText="请选择日期" style="width:90%;"/></td>
        <td style="width:10%;white-space:nowrap;text-align:right;"><span class="as">*</span>性别：</td>
        <td style="width:20%;"><input name="aac004" class="mini-combobox asLabel" valueField="aaa102" textField="aaa103" id="aac004" 
                                      url="${pageContext.request.contextPath }/AC01.do?method=getselect&lx=AAC004"
                                      required="true" emptyText="请选择性别" style="width:90%;"/></td>
    </tr>
    <tr>
        <td style="width:10%;white-space:nowrap;text-align:right;"><span class="as">*</span>民族：</td>
        <td style="width:20%;"><input name="aac005" class="mini-combobox asLabel" valueField="aaa102" textField="aaa103" id="aac005" 
                                      url="${pageContext.request.contextPath }/AC01.do?method=getselect&lx=AAC005" value="01"
                                      required="true" emptyText="请选择民族" style="width:90%;"/></td>
      
        <td style="width:10%;white-space:nowrap;text-align:right;"><span class="as">*</span>国籍或地区：</td>
        <td style="width:20%;"><input name="aac161" class="mini-combobox asLabel" valueField="aaa102" textField="aaa103" id="aac161" 
                                      url="${pageContext.request.contextPath }/AC01.do?method=getselect&lx=AAC161" value="CHN"
                                      required="true" emptyText="请选择国籍或地区" style="width:90%;"/></td>
		<td style="width:10%;text-align:right;white-space:nowrap;"><span class="as">*</span>联系电话：</td>
		<td style="width:20%;"><input name="aae005" class="mini-textbox asLabel"  style="width:90%;" vtype="int;minLength:7" 
									  maxlength="11" required="true" emptyText="请输入联系电话"/></td>

        </tr>
      </table>
    </div>
    <div style="text-align:center;padding:10px;">
      <a class="mini-button"  id="onoks" name="onoks" iconCls="icon-ok"  onclick="onOk" style="width:60px;margin-right:20px;">确定</a>
      <a class="mini-button" onclick="onReset" iconCls="icon-remove" style="width:60px;margin-right:20px;">重置</a>
      <a class="mini-button" id="print" name="print" onclick="view" enabled="false" iconCls="icon-print" style="width:60px;margin-right:20px;">打印</a>
      
        <a class="mini-button" id="card" name="card" onclick="getsfz" enabled="true" iconCls="icon-goto" style="width:100px;margin-right:20px;">读身份证</a>
     
    </div>
  </form>
</fieldset>
<script type="text/javascript">
    mini.parse();
    var form = new mini.Form("form1");   
    var LODOP; //声明为全局变量
    //数据保存
    function SaveData() {
      var o = form.getData();
      form.validate(); 
      if (form.isValid() == false) return;
       if(form.isValid()==true){
      	   mini.mask({el: document.body,cls: 'mini-mask-loading',html: '保存中...'});
      	 }
         var json = mini.encode([o]);      
         $.ajax({
                url: "/zyk/AC01.do?method=saveAC01",
                type: 'post',
                data: { data: json},
                cache: false,
                async:false,
                success: function (text) {                		                      
                		mini.unmask();               		
               			mini.alert(text);  
               		    if(text.indexOf("保存成功") != -1) { 
               		    	labelModel();              		     	                 		      
               			 mini.get("print").setEnabled(true); 
               			 mini.get("onoks").setEnabled(false); 		 
               		   }else{
               		     form.reset();
               		   } 			              			             			              			               			
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    mini.alert(jqXHR.responseText);
                    CloseWindow();
                }
            });
        }
        
        
      
    // 根据所选的证件的类型自动输入国籍并清空其他关联项
    function accept(){
        var zjlx=mini.get("#aac058").getValue();
        if(zjlx == '01'||zjlx == '02'||zjlx == '03') {
            mini.get("#aac161").setValue("CHN");
            mini.getbyName("aac002").setValue("");
            mini.getbyName("aac006").setValue("");
        }else if(zjlx == '04') {
            mini.get("#aac161").setValue("HKG");
            mini.getbyName("aac002").setValue("");
            mini.getbyName("aac006").setValue("");
        }else if(zjlx == '05') {
            mini.get("#aac161").setValue("MAC");
            mini.getbyName("aac002").setValue("");
            mini.getbyName("aac006").setValue("");
        }else if(zjlx == '06') {
            mini.get("#aac161").setValue("TWN");
            mini.getbyName("aac002").setValue("");
            mini.getbyName("aac006").setValue("");
        }else {
            mini.get("#aac161").setValue("");
            mini.getbyName("aac002").setValue("");
            mini.getbyName("aac006").setValue("");
        }
    }
    function onisLength(e){
    	 var aac058=mini.getbyName("aac058").getValue();
        if(aac058== '01'){
        	var pattern=/^(\d{15})$/;
        	if(pattern.test(e.value)){
        	mini.alert("身份证长度错");
        	e.errorText="身份证长度错";
            e.isValid=false;
            mini.getbyName("aac002").setValue("");
            mini.getbyName("aac006").setValue("");
            mini.getbyName("aac004").setValue("");
        	}
        }
    }
   
    //证件重复性和合法性验证
    function onNumber(e){
    	
        var aac002 = mini.getbyName("aac002").getValue().trim();
        var aac058=mini.getbyName("aac058").getValue();
        var flag=false;
        //if(aac058 =='01')
        $.ajax({
            url: "/zyk/AC01.do?method=getaac147",
                dataType : 'JSON',
                data : {aac002:aac002,aac058:aac058},
                async:false, 
                success: function(result) {
                //已经存在该身份证提示用户
                if(result != null && aac058== '01') {
                    mini.alert("证件号码已经存在");
                    mini.getbyName("aac006").setValue("");
                    mini.getbyName("aac004").setValue("");
                    mini.getbyName("aac002").setValue("");
                    flag=false;
                }
               else if(result != null && aac058!= '01') {
                    mini.alert("相同类型的证件号码已经存在");
                    mini.getbyName("aac002").setValue("");
                    flag=false;
                   
                }
                else 
                {
                	//身份证合法性验证
        			if(aac058 == '01'&& aac002!="" ){          
        			 $.ajax({   
         				 url: "/zyk/AC01.do?method=checksfz&id="+ aac002,             
         				 success: function(res){
           	 		 if("0"==res){
            				mini.getbyName("aac006").setValue(e.value.substring(6,10)+'-'+e.value.substring(10,12)+'-'+e.value.substring(12,14));
              	 			 mini.getbyName("aac004").setValue(e.value.substring(16,17)%2?"1":"2");
                
          	 		 }else{
            				mini.alert(res);
             	  		 	mini.getbyName("aac002").setValue("");
            	    		mini.getbyName("aac006").setValue("");
             	   			mini.getbyName("aac004").setValue("");
              	   			return;
          	 		 }                             
          		 }
        		 });   
            
        		}
                }
            }
        });
        
      
    }
    function onBirthday(e){
      var newDate = new Date();
      var aac006 = mini.get("#aac006").getValue();
      var nowDate = newDate.getFullYear()+"/"+((newDate.getMonth()+1)<10?"0":"")+(newDate.getMonth()+1)+"/"+(newDate.getDate()<10?"0":"")+newDate.getDate();
      var now_Date = new Date(Date.parse(nowDate));
      var AAC006 = new Date(Date.parse(aac006));
      if (AAC006 > now_Date) {
         e.errorText = "出生日期超过当前日期";
         e.isValid = false;
       }
    }
    function onOk(e) {
       SaveData();    
    }
    function loading() {
        mini.mask({
            el: document.body,
            cls: 'mini-mask-loading',
            html: '保存中...'
        });
        setTimeout(function () {
            mini.unmask(document.body);
        }, 3000);
    }
    
    function GetData() {
        var o = form.getData();
        return o;
    }
    function onReset(e) {
       form.reset();
       mini.get("onoks").setEnabled(true); 
       mini.get("print").setEnabled(false);
            var fields = form.getFields();
            for (var i = 0, l = fields.length; i < l; i++) {
                var c = fields[i];
                if (c.setReadOnly) c.setReadOnly(false);
                if (c.removeCls) c.removeCls("asLabel");
            }
            mini.repaint(document.body);
        
    }
    
    
    function getsfz() {
    			
				var info=readsfz();
                mini.getbyName("aac003").setValue(info["xm"]);
                mini.getbyName("aac002").setValue(info["sfzhm"]);
                mini.getbyName("aac058").setValue(info["zjlx"]);
                mini.getbyName("aac006").setValue(info["csrq"]);
                mini.getbyName("aac005").setValue(info["mz"]);
                mini.getbyName("aac004").setValue(info["xb"]);
                mini.getbyName("aacc01").setValue(info["zjyxq"]);

    }
    
    
    function view() {
        Preview();
       
    }
	function Preview() {	
	   
	    CreateTwoFormPage();
	  	LODOP.PREVIEW();		
	}
	function CreateTwoFormPage(){
		LODOP=getLodop();
		var aac058=mini.getbyName("aac058").getText().trim();  //证件类型 
		var aac003=mini.getbyName("aac003").getValue().trim();  //姓名
		var aac002=mini.getbyName("aac002").getValue().trim();  //证件号码
		var aac004=mini.getbyName("aac004").getText().trim();  //性别
		var aac005=mini.getbyName("aac005").getText().trim();  //民族
		var aac006=mini.getbyName("aac006").getValue().trim();  //出生日期
		LODOP.PRINT_INITA(-130,-39,1755,1065,"");
		LODOP.ADD_PRINT_TEXT(219,165,200,24,aac058);
		LODOP.SET_PRINT_STYLEA(0,"FontSize",13);
		LODOP.ADD_PRINT_TEXT(219,433,344,28,aac002);
		LODOP.SET_PRINT_STYLEA(0,"FontSize",13);
		LODOP.ADD_PRINT_TEXT(255,164,141,24,aac003);
		LODOP.SET_PRINT_STYLEA(0,"FontSize",13);
		LODOP.ADD_PRINT_TEXT(255,432,69,27,aac004);
		LODOP.SET_PRINT_STYLEA(0,"FontSize",13);
		LODOP.ADD_PRINT_TEXT(255,621,130,25,aac006);
		LODOP.SET_PRINT_STYLEA(0,"FontSize",12);
		LODOP.ADD_PRINT_TEXT(293,163,134,24,aac005);
		LODOP.SET_PRINT_STYLEA(0,"FontSize",13);
		LODOP.ADD_PRINT_TEXT(293,430,70,27,"");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",13);
	}
	function labelModel() {
            var fields = form.getFields();                
            for (var i = 0, l = fields.length; i < l; i++) {
                var c = fields[i];
                if (c.setReadOnly) c.setReadOnly(true);     //只读
                if (c.setIsValid) c.setIsValid(true);      //去除错误提示
                if (c.addCls) c.addCls("asLabel");          //增加asLabel外观
            }
        }
        
          window.onload=function inputModel() {
            var fields = form.getFields();
            for (var i = 0, l = fields.length; i < l; i++) {
                var c = fields[i];
                if (c.setReadOnly) c.setReadOnly(false);
                if (c.removeCls) c.removeCls("asLabel");
            }
            mini.repaint(document.body);
        }
        function isNumber(){
        	var name=mini.getbyName("aac003").getValue();
        	var p=/^([0-9]+)$/;
        	if(name!=""){
        		if(p.exec(name))
                     {
                      mini.alert("姓名不能为数字");
                     mini.getbyName("aac003").setValue(name);
                     name.focus();
                    
                     }
        	
        	}
        
        }

</script>
</body>
</html>